package com.fzshang.shopping.api.controller;


import com.fzshang.shopping.commen.bean.Classification;
import com.fzshang.shopping.commen.bean.Comment;
import com.fzshang.shopping.commen.bean.layuiBean.ResultPage;
import com.fzshang.shopping.commen.bean.layuiBean.VoPage;
import com.fzshang.shopping.commen.controller.BaseController;
import com.fzshang.shopping.commen.entity.ApiResult;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * <p>
 * 评论 前端控制器
 * </p>
 *
 * @author 冯政尚
 * @since 2020-03-13
 */
@Controller
@RequestMapping("admin/comment")
public class CommentController extends BaseController {

    @RequestMapping(value = "comment.html")
    public String comment(){
        return "admin/comment/comment";
    }

    @RequestMapping(value = "comment_add.html")
    public String comment_add(){
        return "admin/comment/comment_add";
    }


    /**
     * @param voPage
     * @return 后台查询
     */
    @RequestMapping(value = "selectMyPage",method = RequestMethod.GET)
    @ResponseBody
    public ResultPage<Comment> selectMyPage(VoPage voPage, Comment comment){
        return commentService.selectMyPage(voPage,comment);
    }

    @RequestMapping(value = "save")
    @ResponseBody
    public ApiResult save(@RequestBody Comment comment){
        comment.setCreateTime(System.currentTimeMillis());
        if(commentService.save(comment)){
            return ApiResult.ok();
        }
        return ApiResult.fail();
    }

    @RequestMapping(value = "deleteById")
    @ResponseBody
    public ApiResult deleteById(Long id){
        if(commentService.removeById(id)){
            return ApiResult.ok();
        }
        return ApiResult.fail();
    }

}
